package puzzle.game.states;

import org.newdawn.slick.Color;
import org.newdawn.slick.Font;
import org.newdawn.slick.GameContainer;
import org.newdawn.slick.Graphics;
import org.newdawn.slick.Image;
import org.newdawn.slick.Input;
import org.newdawn.slick.SlickException;
import puzzle.core.TileFactory;
import puzzle.game.BallPuzzle;
import puzzle.game.states.LoadingState;
import puzzle.game.states.PuzzleState;
import puzzle.util.ResourceManager;

public class HelpState extends PuzzleState {
  
  public static int ID = 5;
  
  protected String escStr = ResourceManager.getString("game.msg.to_main",
                                        "Press ESCAPE for Main Menu");
                      
  public HelpState(BallPuzzle bp) {
    super(bp);
  }
  
  private Image img;
  
  public void initState(GameContainer c) throws SlickException {
    setBackground(TileFactory.GROUND_COLOR);
  }
  
  public void startState(GameContainer c) throws SlickException {
    img = getContext().getLoadingState().getHelpImage();
  }
  
  public void renderState(GameContainer c, Graphics g) {    
    if (img==null)
      return;
      
    int x = c.getWidth()/2 - img.getWidth()/2;
    int y = c.getHeight()/2 - img.getHeight()/2;
    g.drawImage(img, x, y);
    
    int tx = 10;
    int ty = c.getHeight() - g.getFont().getHeight(escStr) - 5;
    g.setColor(Color.white);
    g.drawString(escStr, tx, ty);
  }
  
  public void updateState(GameContainer c, int delta) {
  }
  
  public void keyPressed(int key, char c) {
    super.keyPressed(key, c);
    if (key==Input.KEY_ESCAPE) {
      getContext().enterState(MenuState.ID,
                       this.getExitTransition(),
                       this.getEnterTransition());
    }
  }
  
  public int getID() {
    return ID;
  }
}
